package br.com.leoEarUnpacked.views;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

//### http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F

public class MyConsole {

	private static MessageConsole myConsole = null; // console messages

	private MyConsole() {}

	public static void msg(String msg) {
		String name = "LeoEar Console";

		ConsolePlugin plugin = ConsolePlugin.getDefault();
		IConsoleManager conMan = plugin.getConsoleManager();
		IConsole[] existing = conMan.getConsoles();
		if (myConsole == null) {
			for (int i = 0; i < existing.length; i++)
				if (name.equals(existing[i].getName()))
					myConsole = (MessageConsole) existing[i];
			myConsole = new MessageConsole(name, null);
			conMan.addConsoles(new IConsole[] { myConsole });	
		}
		MessageConsoleStream out = myConsole.newMessageStream();
		out.println(msg);
	}

}
